package com.orkhonsoft.tengrinshar.chat.service;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import com.google.common.collect.ImmutableMap;
import com.orkhonsoft.tengrinshar.chat.entity.UserEntity;
import com.orkhonsoft.tengrinshar.chat.mapper.UserMapper;



@Service("UserService")
public class UserService {
	@Autowired
	private UserMapper usermapper;
	@Autowired
	private StringRedisTemplate redisTemplate;

	public UserEntity queryObject(String id){
		return usermapper.queryUser(id);
	}
	
	public UserEntity getFriendByPhone(String phone){
		return usermapper.queryObject(phone);
	}
	public UserEntity queryUserEntity(Long id){
		return usermapper.queryUser(id);
	}

	public void refreshToken(UserEntity user, String token) {
		String key = "token-" + user.getId();
		redisTemplate.opsForValue().set(key, token);
		redisTemplate.expire(key, 30, TimeUnit.MINUTES);
	}
}
